/*
 * Copyright rgil2010
 * All rights reserved
 */

package com.test.jdbc.connection;

import com.test.appli.mysql.names.Names;
import com.test.jdbc.Def;

/**
 *
 * @author user
 */
public class ConCreateDB extends ConAbs{
    public ConCreateDB() throws Exception {
        super();
    }


    @Override
    public boolean doJob() throws Exception{
       this._dbConnection_.connect("", "root", "0");
       this._dbConnection_.executeUpdate(Def.createDB(Names.db));
       this._dbConnection_.executeUpdate(Def.useDB(Names.db));

        String strCommandCreateProprietaire =
            Def.createTable(Names.tablePrt)+
            Def.createField("id", Def.typId)+
            Def.createField("nom", Def.typVarchar(20)) +
            Def.createField("prenom1", Def.typVarchar(20)) +
            Def.createField("prenom2", Def.typVarchar(20)) +
            Def.createField("prenom3", Def.typVarchar(20)) +
            Def.createField("sexe",  Def.typChar(1)) +
            Def.createField("dateNaissance", Def.typDate()) +
            Def.createField("adresseEmailPerso",   Def.typVarchar(20)) +
            Def.createField("adresseEmailTravail",   Def.typVarchar(20)) +
            Def.createField("telPerso",   Def.typVarchar(20)) +
            Def.createField("tetTravail",   Def.typVarchar(20)) +
            Def.createField("portablePerso",   Def.typVarchar(20)) +
            Def.createField("portableTravail",   Def.typVarchar(20)) +
            Def.createField("nomRue",   Def.typVarchar(20)) +
            Def.createField("numeroDeRue",   Def.typVarchar(4)) +
            Def.createField("ligneCourrier1",   Def.typVarchar(20)) +
            Def.createField("ligneCourrier2",   Def.typVarchar(20)) +
            Def.createField("codePostal",  Def.typChar(5)) +
            Def.createField("ville",   Def.typVarchar(20)) +
            Def.createLastField("pays",   Def.typVarchar(20));

        String strCommandCreateAnimal =
            Def.createTable(Names.tableAnm)+
            Def.createField("id",  Def.typId) +
            Def.createField("nom",  Def.typVarchar(20)) +
            Def.createField("sexe",  Def.typChar(1)) +
            Def.createField("proprietaire",  Def.typRefId(Names.tablePrt,"id")) +
            Def.createField("castre",  Def.typChar(1)) +
            Def.createField("espece",   Def.typVarchar(20)) +
            Def.createField("race",   Def.typVarchar(20)) +
            Def.createField("dateNaissance", Def.typDate()) +
            Def.createLastField("dateMort", Def.typDate());

        String strCommandCreateUser =
            Def.createTable(Names.tableUsr)+
            Def.createField("id", Def.typId)+
            Def.createField("nom", Def.typVarchar(20)) +
            Def.createField("prenom1", Def.typVarchar(20)) +
            Def.createField("prenom2", Def.typVarchar(20)) +
            Def.createField("prenom3", Def.typVarchar(20)) +
            Def.createField("groupe", Def.typVarchar(3)) +
            Def.createField("dateNaissance", Def.typDate()) +
            Def.createField("sexe",  Def.typChar(1)) +
            Def.createField("adresseEmailPerso",   Def.typVarchar(20)) +
            Def.createField("adresseEmailTravail",   Def.typVarchar(20)) +
            Def.createField("telPerso",   Def.typVarchar(20)) +
            Def.createField("tetTravail",   Def.typVarchar(20)) +
            Def.createField("portablePerso",   Def.typVarchar(20)) +
            Def.createField("portableTravail",   Def.typVarchar(20)) +
            Def.createField("nomRue",   Def.typVarchar(20)) +
            Def.createField("numeroDeRue",   Def.typVarchar(4)) +
            Def.createField("ligneCourrier1",   Def.typVarchar(20)) +
            Def.createField("ligneCourrier2",   Def.typVarchar(20)) +
            Def.createField("codePostal",  Def.typChar(5)) +
            Def.createField("ville",   Def.typVarchar(20)) +
            Def.createField("pays",   Def.typVarchar(20)) +
            Def.createField("login",  Def.typVarchar(20)) +
            Def.createLastField("password",  Def.typVarchar(20));

            this._dbConnection_.executeUpdate(strCommandCreateProprietaire);
            this._dbConnection_.executeUpdate(strCommandCreateAnimal);
            this._dbConnection_.executeUpdate(strCommandCreateUser);
            this._dbConnection_.disconnect();

            return true;

    }


    
}
